import QtQuick 2.6 as Q
import QtQuick.Window 2.2


//!
//  替代默认TextInput的一种输入框，修复了一些不协调的问题
//  该类主要是在Android中使用。QtQuick中默认的TextInput有时会被键盘顶开，使用这个则永远不会
//  example:
//  @code
//  @code
// /
Q.Item {
    id: root
    property alias acceptableInput: input.acceptableInput
    property alias activeFocusOnPress: input.activeFocusOnPress
    property alias autoScroll: input.autoScroll
    property alias bottomPadding: input.bottomPadding
    property alias canPaste: input.canPaste
    property alias canRedo: input.canRedo
    property alias canUndo: input.canUndo
    property alias color: input.color
    property alias contentHeight: input.contentHeight
    property alias contentWidth: input.contentWidth
    property alias cursorDelegate: input.cursorDelegate
    property alias cursorPosition: input.cursorPosition
    property alias cursorRectangle: input.cursorRectangle
    property alias cursorVisible: input.cursorVisible
    property alias displayText: input.displayText
    property alias echoMode: input.echoMode
    property alias effectiveHorizontalAlignment: input.effectiveHorizontalAlignment
    property alias font: input.font
    property alias horizontalAlignment: input.horizontalAlignment
    property alias inputMask: input.inputMask
    property alias inputMethodComposing: input.inputMethodComposing
    property alias inputMethodHints: input.inputMethodHints
    property alias leftPadding: input.leftPadding
    property alias length: input.length
    property alias maximumLength: input.maximumLength
    property alias mouseSelectionMode: input.mouseSelectionMode
    property alias padding: input.padding
    property alias passwordCharacter: input.passwordCharacter
    property alias passwordMaskDelay: input.passwordMaskDelay
    property alias persistentSelection: input.persistentSelection
    property alias readOnly: input.readOnly
    property alias renderType: input.renderType
    property alias rightPadding: input.rightPadding
    property alias selectByMouse: input.selectByMouse
    property alias selectedText: input.selectedText
    property alias selectedTextColor: input.selectedTextColor
    property alias selectionColor: input.selectionColor
    property alias selectionEnd: input.selectionEnd
    property alias selectionStart: input.selectionStart
    property alias text: input.text
    property alias topPadding: input.topPadding
    property alias validator: input.validator
    property alias verticalAlignment: input.verticalAlignment
    property alias wrapMode: input.wrapMode

    signal accepted
    signal editingFinished

    onActiveFocusChanged: {
        if (activeFocus) {
            input.forceActiveFocus()
            keyboard.show()
        }
    }

    Q.TextInput {
        id: input
        property bool shown: y === 0
        onAccepted: root.accepted()
        onEditingFinished: root.editingFinished()

        width: parent.width
        height: parent.height
        y: keyboard.visible && activeFocus || Qt.platform.os === "windows" ? 0 : -Screen.height

        selectByMouse: true
    }
    Q.TextInput {
        id: input2

        visible: !input.shown
        anchors.fill: parent

        activeFocusOnPress: input.activeFocusOnPress
        autoScroll: input.autoScroll
        bottomPadding: input.bottomPadding
        color : input.color
        //color: "red"
        cursorDelegate: input.cursorDelegate
        cursorVisible: input.cursorVisible
        echoMode: input.echoMode
        font: input.font
        horizontalAlignment: input.horizontalAlignment
        inputMask: input.inputMask
        inputMethodHints: input.inputMethodHints
        leftPadding: input.leftPadding
        maximumLength: input.maximumLength
        mouseSelectionMode: input.mouseSelectionMode
        padding: input.padding
        passwordCharacter: input.passwordCharacter
        passwordMaskDelay: input.passwordMaskDelay
        persistentSelection: input.persistentSelection
        readOnly: true
        renderType: input.renderType
        rightPadding: input.rightPadding
        selectByMouse: input.selectByMouse
        selectedTextColor: input.selectedTextColor
        selectionColor: input.selectionColor
        text: input.text
        topPadding: input.topPadding
        validator: input.validator
        verticalAlignment: input.verticalAlignment
        wrapMode: input.wrapMode
    }
    Q.MouseArea {
        id: vkhelper
        visible: !input.shown
        anchors.fill: parent
        z: 1
        onPressed: {
            input.forceActiveFocus()
            keyboard.show()
        }
    }
    Q.QtObject {
        id: keyboard

        property bool visible: Qt.inputMethod.visible

        function show() {
            Qt.inputMethod.show()
        }
    }
}
